package com.yidu.InventoryManagement.controller;

import com.yidu.InventoryManagement.Util.IdUtil;
import com.yidu.InventoryManagement.entity.SecurityAccrualStock;

import com.yidu.InventoryManagement.service.securityAccrualStockService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.sound.midi.Soundbank;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author z
 * @version 1.0
 * @date 2022/12/5
 */
@RestController
public class securityAccrualStockController {
    @Resource
    private securityAccrualStockService securityAccrualStockService;

    /**
     * 分页查询
     * @param page 页码
     * @param limit 每页条数
     * @param
     * @param
     * @return
     */

    @RequestMapping("/selectSecuritiesInventoryInfo")
    public Map<String,Object> selectSecuritiesInventoryInfo(int limit, int page,String date,String securityType){
        return securityAccrualStockService.selectSecuritiesInventory(limit,page,date,securityType);
    }
    //数据新增
  /*  @RequestMapping("/addSecuritiesInventoryInfo")
    public int addSecuritiesInventoryInfo(SecurityAccrualStock securityAccrualStock){
        System.out.println("se===="+securityAccrualStock);//这句话证明进了这个控制器
        int i = securityAccrualStockService.addSecuritiesInventoryInfo(securityAccrualStock);
        System.out.println("i===="+i);
        return i;
    }*/
    //修改
    @RequestMapping("/updateSecuritiesInventoryInfo")
    public int updateSecuritiesInventoryInfo(SecurityAccrualStock securityAccrualStock){
        System.out.println("修改"+securityAccrualStock);
        int i=securityAccrualStockService.updateSecuritiesInventoryInfo(securityAccrualStock);
        if(i>0){
            System.out.println("修改成功"+i);
        }else{
            System.out.println("修改失败"+i);
        }
        return i;
    }
    //删除通过id删除
    @RequestMapping("/deleteSecuritiesInventoryInfo")
    public int deleteSecuritiesInventoryInfo(String securityAccrualStockId){
        System.out.println("进来了删除的方法"+securityAccrualStockId);
        int i = securityAccrualStockService.deleteSecuritiesInventoryInfo(securityAccrualStockId);

        if(i>0){
            System.out.println("删除成功"+i);
        }else{
            System.out.println("删除失败"+i);
        }
        return i;
    }

    //添加
    @RequestMapping("/addSecuritiesInventoryInfo")
    public int addSecuritiesInventoryInfo(SecurityAccrualStock securityAccrualStock){
        System.out.println("进来了添加88888"+securityAccrualStock);
        int s = securityAccrualStockService.selectSecurityAccrualStockId();
        System.out.println(s+"]]]]]]]]");
        int i=0;
        if(s==0){
            String id="SA2022120511";
           securityAccrualStock.setSecurityAccrualStockId(id);
             i = securityAccrualStockService.addSecuritiesInventoryInfo(securityAccrualStock);
        }else{
            String s1 = securityAccrualStockService.getmaxsecurityAccrualStockId().substring(2,12);
            System.out.println(s1+"SSSSSS");
            IdUtil idUtil=new IdUtil();
            String id = "SA"+idUtil.createID(s1);
             securityAccrualStock.setSecurityAccrualStockId(id);
            i = securityAccrualStockService.addSecuritiesInventoryInfo(securityAccrualStock);
        }
        return i;
    }




    /**
     * 下拉表格的查询基金信息
     * @param page 当前页
     * @param limit 每页显示数
     * @param fundName 证券名称
     * @return list 集合
     */
    @RequestMapping("selectFundIdAndFundName")
    public Map selectFundIdAndFundName(int page, int limit, String fundName) {
        return securityAccrualStockService.selectFundIdAndFundName(page,limit,fundName);
    }
    /**
     * 下拉表格的查询证券信息
     * @param page 当前页
     * @param limit 每页显示数
     * @param securityName 证券名称
     * @return list 集合
     */
    @RequestMapping("selectSecurityIdAndSelectSecurityName")
    public Map selectSecurityIdAndSelectSecurityName(int page, int limit, String securityName) {
        return securityAccrualStockService.selectSecurityIdAndSelectSecurityName(page,limit,securityName);
    }

}

